<template>
  <div class="manageDiv">
    <!-- 顶部导航菜单 -->
    <el-menu
      class="manage-menu"
      mode="horizontal"
      :default-active="activeIndex"
      @select="handleSelect"
    >
      <el-menu-item index="userPage">用户</el-menu-item>
      <el-menu-item index="keysPage">卡密</el-menu-item>
      <el-menu-item index="addPage">添加</el-menu-item>
      <el-menu-item index="versionPage">版本</el-menu-item>
      <el-menu-item index="QuestionPage">题库</el-menu-item>
    </el-menu>

    <!-- 内容区域 -->
    <div>
      <router-view />
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

// 当前选中的菜单 index
const activeIndex = ref<string>('userPage')

const handleSelect = (index: string) => {
  activeIndex.value = index

  if (index === 'userPage') router.push({ name: 'AdminUser' })
  else if (index === 'keysPage') router.push({ name: 'AdminKeys' })
  else if (index === 'addPage') router.push({ name: 'AdminAdd' })
  else if (index === 'versionPage') router.push({ name: 'AdminVersion' })
  else if (index === 'QuestionPage') router.push({ name: 'AdminQuestion' })
}

onMounted(() => {
  const a = localStorage.getItem('a')
  const b = localStorage.getItem('b')
  if (!a || !b) {
    router.push({ name: 'AdminLogin' })
  } else {
    // 默认进入用户管理子页
    router.push({ name: 'AdminUser' })
    activeIndex.value = 'userPage'
  }
})
</script>

<style scoped>

</style>